﻿using System.Drawing;
using System.Windows.Forms;

namespace Marmat.Forms
{
    public class TreeViewRenderer
    {
        public TreeViewRenderer(TreeView TreeView)
        {
            this.TreeView = TreeView;
        }

        public TreeView TreeView { get; set; }

        /// <summary>
    /// 绘制背景时发生
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        protected virtual void OnPaint(PaintEventArgs e)
        {
        }

        /// <summary>
    /// 绘制背景时发生
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        internal void RaiseOnPaint(PaintEventArgs e)
        {
            this.OnPaint(e);
        }

        /// <summary>
    /// 绘制目录节点的矩形时发生
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        protected virtual void OnTreeNodePaint(PaintTreeNodeEventArgs e)
        {
            // If e.Node Is e.Node.TreeView.Nodes(1) Then
            // e.Height = 30
            // 'e.Graphics.DrawRectangle(Pens.Red, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width - 1, 30)
            // Exit Sub
            // End If
            // e.Graphics.DrawRectangle(Pens.Red, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height)
        }
        /// <summary>
    /// 绘制背景时发生
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        internal void RaiseOnTreeNodePaint(PaintTreeNodeEventArgs e)
        {
            this.OnTreeNodePaint(e);
        }

        /// <summary>
    /// 绘制加减符时发生
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        protected virtual void OnPlusMinusPaint(PaintShowPlusMinusEventArgs e)
        {
            Image Image = Properties.Resources.treeView_fold;
            if (e.Node.IsExpanded == true)
            {
                Image = Properties.Resources.treeView_unfold;
            }

            e.Image = Image;
        }
        /// <summary>
    /// 绘制加减符时发生
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        internal void RaiseOnPlusMinusPaint(PaintShowPlusMinusEventArgs e)
        {
            this.OnPlusMinusPaint(e);
        }

        /// <summary>
    /// 绘制复选框时发生
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        protected virtual void OnCheckBoxes(TreeViewPaintCheckBoxesEventArgs e)
        {
        }
        /// <summary>
    /// 绘制复选框时发生
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        internal void RaiseOnCheckBoxes(TreeViewPaintCheckBoxesEventArgs e)
        {
            this.OnCheckBoxes(e);
        }
    }
}